
#include"goods.h"
#include"mainwindow.h"

#include <QApplication>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QMessageBox>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("../storemanagement/mysql/my.db");
    if(false==db.open())
    {
        QMessageBox::critical(0,"连接失败","无法连接到数据库",QMessageBox::Cancel);
    }
    QSqlQuery query;
    query.exec("pragma foreign_keys=on");
//    query.exec("create table users(id varchar primary key,pwd varchar)");
    query.exec("insert into users values('root','123456')");
//    query.exec("create table worker(id varchar primary key,name varchar,year varchar,address varchar"
//               ",phone varchar,gzzw varchar,gz varchar )");
    query.exec("create table category(categoryid int primary key,name varchar)");
    query.exec("create table goods(id int primary key,categoryid int,name varchar,price double,num int,picture blob,foreign key(categoryid) references category)");
    int categoryid=0;
    QString name="test";
    query.exec(QString("insert into category(categoryid,name)values(%1,'%2')").arg(categoryid).arg(name));
    mainwindow w;
    w.show();
    return a.exec();
}
